# 问题控制器，负责协调调用DAO对象，完成复杂的业务逻辑
from typing import List
from dbs.qstn_dao import QstnDao
from dbs.option_dao import OptionDao

class QstnMgmt(object):
    def __init__(self):
        self.name = 'mgmt.qstn_mgmt.QstnMgmt'

    @staticmethod
    def add_single(data) -> int:
        print(f'添加单选题 v0.0.1')
        params = {}
        params['notes'] = 'nnn'
        params['qstn_title'] = data['title']
        QstnDao.add_qstn(params=params)
        # 添加选项
        for opt in data['single']['options']:
            opt_params = {'opt_text': opt['content']}
            OptionDao.add_option(params=opt_params)

    @staticmethod
    def get_qstn_by_id(qstn_id) -> List:
        return QstnDao.get_qstn_by_id(qstn_id)
    
    @staticmethod
    def get_qstn_options(qstn_id) -> List:
        return OptionDao.get_qstn_options(qstn_id)